package com.zy.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zy.entity.Branch;
import com.zy.entity.Department;
import com.zy.mapper.DepartmentMapper;
import com.zy.service.DepartmentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class DepartmentServiceImpl implements DepartmentService {

    @Resource
    DepartmentMapper departmentMapper;

    @Override
    public Department getById(Integer id) {
        return (Department)this.departmentMapper.selectByPrimaryKey(id);
    }

    @Override
    public void save(Department department) {
        this.departmentMapper.insert(department);
    }

    @Override
    public void updateById(Department department) {
        this.departmentMapper.updateByPrimaryKey(department);
    }

    @Override
    public PageInfo<Department> page(Department department, Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        return new PageInfo(this.departmentMapper.page(department));
    }

    @Override
    public void delete(Integer id) {
        this.departmentMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void status(Integer id) {
        Department department = departmentMapper.selectByPrimaryKey(id);
        department.setDpStatus(department.getDpStatus()==0?1:0);
        this.departmentMapper.updateByPrimaryKey(department);
    }
}
